﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Hospital_TraPurchasePlanAdd : System.Web.UI.Page, HZ.MBSM.BLL.TraDes
{
    private Int64 AccountId;
    protected void Page_Load(object sender, EventArgs e)
    {
        //_strProjectId = SysFun.ToTrim(Request.QueryString["ProjectId"]);
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumHospitale);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                AccountId = _Account.AccountId;
                HZ.MBSM.DBUtility.Db db = new HZ.MBSM.DBUtility.Db(false);
                Grove.ORM.ObjectOperator oo = db.GetObjectOperator();
                HZ.MBSM.Model.Hospital Hospital = (HZ.MBSM.Model.Hospital)oo.Retrieve(typeof(HZ.MBSM.Model.Hospital), AccountId);
                if (_Account != null)
                {
                    string _strHospitalName = _Account.DWName;
                    txtPlanName.Text = _strHospitalName + System.DateTime.Now.ToShortDateString() + "采购单";
                    TextLname.Text = Hospital.LinkMan;
                    TextPhote.Text = Hospital.Telephone;
                    TextJName.Text = Hospital.listman;
                    oo.Dispose();
                }
            }
        }
    }





    protected void BtnSave_Click(object sender, EventArgs e)
    {

        if (DateTime.Parse(SysFun.ToTrim(txtStartTime.Text)) > DateTime.Parse(SysFun.ToTrim(txtEndTime.Text)))
        {
            Response.Write("<script>window.alert('开始时间不得晚于结束时间');</script>");
            return;
        }
        if (DateTime.Parse(SysFun.ToTrim(txtStartTime.Text)).Date < DateTime.Now.Date)
        {
            Response.Write("<script>window.alert('开始时间不得早于当前时间');</script>");
            return;
        }
        if (SysFun.ToTrim(TextLname.Text) == "")
        {
            Response.Write("<script>window.alert('联系人必填！');</script>");
            return;
        }
        if (SysFun.ToTrim(TextPhote.Text) == "")
        {
            Response.Write("<script>window.alert('联系电话！');</script>");
            return;
        }
        if (SysFun.ToTrim(TextJName.Text) == "")
        {
            Response.Write("<script>window.alert('建单人！');</script>");
            return;
        }
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        string _strSql, _strPlanName;
        _strPlanName = SysFun.ToTrim(txtPlanName.Text);
        _strSql = "select PlanName from purchaseplan where PlanName='" + _strPlanName + "' ";
        Db db = new Db();
        System.Data.IDataReader dr;
        dr = db.DataReader(_strSql);
        if (dr.Read())
        {
            Response.Write("<script>window.alert('已经有此采购单名称，请重新命名！');</script>");
            dr.Close();
            dr.Dispose();
            db.Close();
            dr = null;
            db = null;
            return;
        }
        dr.Close();
        dr.Dispose();
        string _strendtime = WebUserTime1.StrMy;
        //_strSql = "insert into PurchasePlan(PlanName,Projectid,AccountId_YY,StartTime,EndTime,Remarks,BuildTime,BuyStatus) values(";
        //_strSql += "'" + _strPlanName + "'," + _strProjectId + "," + _Account.AccountId + ",'" + SysFun.ToTrim(txtStartTime.Text) + "','" + SysFun.ToTrim(txtEndTime.Text) + "','" + SysFun.ToTrim(txtRemarks.Text) + "','" + System.DateTime.Now + "','0')";
        // 2007/08/21  马毅
        _strSql = "insert into PurchasePlan(PlanName,Projectid,AccountId_YY,StartTime,EndTime,Remarks,BuildTime,BuyStatus,RelationMen,RelationPhone,ConstructMen) values(";
        _strSql += "'" + _strPlanName + "',0," + _Account.AccountId + ",'" + SysFun.ToTrim(txtStartTime.Text) + "','" + SysFun.ToTrim(txtEndTime.Text.Trim() + " " + _strendtime) + "','" + SysFun.ToTrim(txtRemarks.Text) + "','" + System.DateTime.Now + "','0','" + SysFun.ToTrim(TextLname.Text) + "','" + SysFun.ToTrim(TextPhote.Text) + "','" + SysFun.ToTrim(TextJName.Text) + "')";


        db.Command(_strSql);
        db.Close();
        db = null;
        //  Response.Write("<script>window.alert('新增成功');window.location.href='TraPurchasePlanList.aspx?ProjectId=" + _strProjectId + "';</script>");
        // 2007/08/21  马毅
        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "插入", "PurchasePlan", _strSql, "..Hospital/TraPurchasePlanAdd.aspx");
        Response.Write("<script>window.alert('新增成功');</script>");
        Response.Redirect("TraPurchasePlanList.aspx?ProjectId=" + SysFun.IsSQL((Request.QueryString["ProjectId"])));


    }

    #region TraDes 成员

    public string Name
    {
        get { return "新增采购单"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "采购单管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumHospitale);
            return _AccountType;
        }
    }

    #endregion
}
